//pages/index/index.js
var api=require('../../utils/api.js');
var sliderWidth=96;
Page({
	data: {
		tabs: ["简约","中式","欧式","美式"],
		activeIndex: 0,
		loupanlist: [],
		gongyilist: [],
		anlilist: [],
		adviserlist: [],
		after_service: [],
		stylecases: [[],[],[],[]],
		isshow: false,
		citys: [],
		index: -1,
		intdata: ''
	},
	loadswiper(){
		api.get({
			url: 'home/slider/1',
			success: data=>{
				console.log(data)
				if(data.code==1){
					this.setData({
						movies: data.data[0].items
					})
				}
			}
		});
	},
	loadcailiao(){
		api.get({
			url: 'home/slides/41',
			success: data=>{
				if(data.code==1){
					this.setData({
						cailiao: data.data[0].items
					})
				}
			}
		});
	},

//生命周期函数
	onload: function(options){
		this.loadswiper();
		this.loadloupan();
		this.loadcases();
		this.loadfuwu();
		this.load3dcase();
		this.loadafterservice();
		this.loadadviser();
		this.loadgongyi();
		this.onlineform=this.seleteComponent("#onlineform");
		api.getparams();
		this.loadcailiao();
	},
	tabClick: function(e){
		this.setData({
			activeIndex: e.currentTarget.id
		});
	},
	loadfuwu(){
		api.get({
			url: 'home/slides/3',
			success: data=>{
				if(data.code==1){
					this.setData({
						fuwulist: data.data[0].items
					})
				}
			}
		});
	},

	loadafterservice(){
		api.get({
			url: 'home/slides/4',
			success: data=>{
				if(data.code==1){
					this.setData({
						after_service: data.data[0].items
					})
				}
			}
		});
	},
	load3dcase(){
		api.get({
			url: '/portal/lists/getCategoryPositions',
			data: {
				category_id: 4,
				filed: 'post.id,post.post_title,post_name',
				is_top: 1,
				limit: 1,
				order: '-post.id'
			},
			success: data=> {
				console.log(data.data)
				if(data.code=='1'){
					this.setData({
						case3d: data.data.list[0]
					})
				}
			}
		})
	},

	loadgongyi(){
		api.get({
			url: '/portal/lists/getCategoryPostList',
			data:{
				category_id: 0,
				filed: 'post.id,post.post_title,post.more',
				is_top: 1;
				order: '-post.id'
			},
			success: data=>{
				if(data.code=='1'){
					this.setData({
						gongyilist: data.data.list
					})
				}
			}
		})
	},

	formSubmit(e){
		console.log(e)
		api.post({
			url: '/portal/ditform/insert2',
			data: e.detail.value,
			success: data=>{
				if(data.code=="1"){
					wx.showToast({title: '报名成功', icon: 'success'})
				}
				if(data.code=="0"){
					wx.showToast({title: data.msg, icon: 'none'})
				}
			}
		})
	},

	openswith(){
		wx.switchTab({
			url: '/pages/about/index',
		})
	},
	onTabItemTap(e){
		console.log(e)
		if(e.index==2){
			var params=wx.getStorageSync("params");
			wx.makePhoneCall({
				phoneNumber: params['tel']
			})
		}
	},
	previewimage(e){
		var imgurl=e.currentTarget.dataset.url
		wx.previewImage({
			current: imgurl,
			urls: [imgurl]
		})
	},
	onReady: function(){

	},

	onShow: function(){
		wx.switchTab({
			url: '/pages/index/iondex',
		})
	},

	loadloupan(){
		api.get({
			url: '/portal/lists/getCategoryPostLists',
			data:{
				category_id: 1,
				filed: 'post.id, post.post_title, post.post_more',
				is_top,
				order: '-post_id'
			},
			success: data=>{
				if(data.code=='1'){
					this.setData({
						loupanlist: data.data.list
					})
				}
			}
		})
	},

	loadadviser(){
		api.get({
			url: '/portal/lists/getCategoryPostLists',
			data: {
				category_id: 7,
				filed: 'post.id, post.post_title,post.more',
				is_top: 1,
				order: '-post.id'
			},
			success: data=>{
				if(data.code=='1'){
					this.setData({
						adviserlist: data.data.list
					})
				}
			}
		})
	},

	loadcases(){
		api.get({
			url: '/portal/lists/getCategoryPostLists',
			data: {
				category_id: 2,
				filed: 'post.id,post.post_title,post.more',
				is_top: 1,
				limit: 12,
				order: '+list_order'
			},
			success: data=>{
				if(data.code=='1'){
					let styleceses=this.data.styleceses;
					let arr=data.data.list;
					for(var i=0;i<arr.length;i++){
						stylecases[arr[i].more.style].push(arr[i])
					}
					this.setData({
						stylecases: stylecases
					})
				}
			}
		})
	},


	onHide: function(){},
	onUnload: function(){},
	onPullDownRefresh: function(){},
	onReachBottom: function(){},
	onShareAppMessage: function(){}
})